package neu.soft.controller;

import neu.soft.entity.OperationWarehouse;
import neu.soft.exception.AppException;
import neu.soft.exception.AppExceptionCodeMsg;
import neu.soft.feignclient.WarehouseFeignClient;
import neu.soft.query.WarehousePageQuery;
import neu.soft.service.WarehouseService;
import neu.soft.vo.PageBean;
import neu.soft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/warehouse")
@CrossOrigin
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;

    @PostMapping
    public ResultBean addwarehouse(@RequestBody OperationWarehouse operationWarehouse){

        int res = warehouseService.addWarehouse(operationWarehouse);
        return ResultBean.success("库房登记成功");
    }

    @PutMapping
    public ResultBean updatewarehouse(@RequestBody OperationWarehouse operationWarehouse){
        int res = warehouseService.updateWarehouse(operationWarehouse);
        return ResultBean.success("库房信息更新成功");
    }

    @DeleteMapping
    public ResultBean deleteWarehouse(Integer warehouseId){
        if (warehouseId==null){
            throw new AppException(AppExceptionCodeMsg.REQUEST_PARAM_EMPTY);
        }
        int res = warehouseService.deleteWarehouse(warehouseId);
        return ResultBean.success("库房删除成功");
    }

    @PostMapping("/page")
    public ResultBean<PageBean<OperationWarehouse>> findByPage(@RequestBody WarehousePageQuery warehouseQuery) {

        PageBean<OperationWarehouse> warehouseList = warehouseService.findByPage(warehouseQuery);
        return ResultBean.success(warehouseList);
    }

//    @PostMapping("/info")
//    public ResultBean findInOutStackInfo(@RequestBody Map<String,Object> infoMap){
//        return warehouseFeignClient.queryEntryOrder(infoMap);
//    }

}
